package com.Ajava1704.for设计模式.for动态代理.jdk动态代理;

import java.lang.reflect.Proxy;

/**
 * @类名: com.Ajava1704.for设计模式.for动态代理.jdk动态代理
 * @作者: lgt
 * @创建时间: 2020-02-14 20:58
 * @描述:
 **/
public class ForTest001 {
    public static void main(String[] args) {
        //为接口创建代理类
        /*
        ForMyInvocationHandler forMyInvocationHandler = new ForMyInvocationHandler();
        Class<?>[] interfaces = {ForTestInterface.class};
        ForTestInterface o = (ForTestInterface) Proxy.newProxyInstance(ForTestInterface.class.getClassLoader(), interfaces, forMyInvocationHandler);
        System.out.println(o.test());
        */


        //为借口的实现类创建代理对象
        ForTestInterfaceImpl forTestInterface = new ForTestInterfaceImpl();
        ForMyInvovationHandler2<ForTestInterfaceImpl> forMyInvovationHandler2 = new ForMyInvovationHandler2<>(forTestInterface);
//      ForTestInterface o1 = (ForTestInterface) Proxy.newProxyInstance(ForTestInterface.class.getClassLoader(), ForTestInterfaceImpl.class.getInterfaces(), forMyInvovationHandler2);
//      System.out.println(o1.test());


        ForTestTTT<ForTestInterface> objectForTestTTT = new ForTestTTT<>();
        ForTestInterface proxyObject = objectForTestTTT.getProxyObject(ForTestInterfaceImpl.class.getClassLoader(), ForTestInterfaceImpl.class.getInterfaces(), forMyInvovationHandler2);
        System.out.println(proxyObject.test());
    }
}
